package com.dubbo.privoder;

import com.dubbo.protocol.Server;
import com.dubbo.protocol.ServerFactory;
import com.dubbo.protocol.http.HttpServer;
import com.dubbo.register.RegisterFactory;
import com.dubbo.register.RemoteRegister;
import com.dubbo.service.impl.UserServiceImpl;

import java.net.URL;
import java.util.Map;

public class Provider
{
    public static void main(String[] args) throws Exception
    {
        //服务端扫描所有对外提供rpc服务，key=接口名，value=实现类
        Map<String, Object> localRegister = RegisterFactory.get(RegisterFactory.LOCAL);
        localRegister.put("com.dubbo.service.UserService", UserServiceImpl.class);//本地注册器，保存map（接口，实现类）

        //网络注册中心，保存key=接口名，value=URL对象
        RemoteRegister remoteRegister = RemoteRegister.getInstance();
        URL url = new URL("http", "localhost", 8090,"/");
        remoteRegister.put("com.dubbo.service.UserService", url);

        Server server = ServerFactory.get(ServerFactory.HTTP);
        server.start("localhost", 8090);
    }
}
